<?php


if ( function_exists('register_sidebar') ) {

register_sidebar(array('name'=>'Off Canvas Sidebar',
'id' => 'sidebar',
			'description' => __('Off Canvas Sidebar', 'redox_localize'),
			'before_widget' => '<div class="widget post">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>'
));

}

function redox_fonts() {
    wp_register_style('redoxFonts', 'http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic');
    wp_enqueue_style( 'redoxFonts');
}

add_action('wp_print_styles', 'redox_fonts');

add_theme_support('post-formats', array( 
	'aside', 
	'chat', 
	'gallery', 
	'image', 
	'link', 
	'quote', 
	'video'
));

function redox_register_menus() {
  register_nav_menu('redox_menu',__( 'Primary Navigation' ));
}
add_action( 'init', 'redox_register_menus' );
if ( ! isset( $content_width ) ) $content_width = 1360;

require_once(TEMPLATEPATH . '/functions/comments_set_up.php');
require_once(TEMPLATEPATH . '/functions/gallery.php');
require_once(TEMPLATEPATH . '/functions/meta_boxes.php');
require_once(TEMPLATEPATH . '/functions/user_colors.php');


require_once(TEMPLATEPATH . '/admin/admin-functions.php');
require_once(TEMPLATEPATH . '/admin/admin-interface.php');
require_once(TEMPLATEPATH . '/admin/theme-settings.php');

require_once(TEMPLATEPATH . '/widgets/widget-author.php');

require_once(TEMPLATEPATH . '/widgets/widget-twitter.php');
require_once(TEMPLATEPATH . '/widgets/widget-social.php');

add_theme_support( 
	'automatic-feed-links' 
);

add_theme_support( 
	'post-thumbnails' 
); 

function redoxStyles()
{
	wp_register_style( 'reset', get_template_directory_uri() . '/css/reset.css', array(), 'all' );
	wp_register_style( 'icons', get_template_directory_uri() . '/css/icons.css', array(), 'all' );
	wp_register_style( 'fancybox', get_template_directory_uri() . '/css/fancybox.css', array(), 'all' );
	wp_register_style( 'default', get_bloginfo( 'stylesheet_url' ), array(), 'all' );

	wp_enqueue_style( 'reset' );
	wp_enqueue_style( 'icons' );
	wp_enqueue_style( 'fancybox' );
	wp_enqueue_style( 'default' );
}

add_action( 'wp_enqueue_scripts', 'redoxStyles' );


function redox_jQuery() {
    wp_enqueue_script('jquery');   
}

add_action('init', 'redox_jQuery');

function redox_scripts() {

	wp_enqueue_script(
		'fitvids',
		get_template_directory_uri() . '/js/jquery.fitvids.js',
		array( 'jquery' )
	);

	wp_enqueue_script(
		'isotope',
		get_template_directory_uri() . '/js/jquery.isotope.min.js',
		array( 'jquery' )
	);

	wp_enqueue_script(
		'fancybox',
		get_template_directory_uri() . '/js/jquery.fancybox.pack.js',
		array( 'jquery' )
	);
	wp_enqueue_script(
		'fancyboxmedia',
		get_template_directory_uri() . '/js/jquery.fancybox-media.js',
		array( 'jquery' )
	);
	wp_enqueue_script(
		'fancyboxthumbs',
		get_template_directory_uri() . '/js/jquery.fancybox-thumbs.js',
		array( 'jquery' )
	);
        wp_enqueue_script(
		'uiposition',
		get_template_directory_uri() . '/js/jquery.ui.position.js',
		array( 'jquery' )
	);
         wp_enqueue_script(
		'blockUI',
		get_template_directory_uri() . '/js/jquery.blockUI.js',
		array( 'jquery' )
	);
}

add_action( 'get_footer', 'redox_scripts' );

function redox_sharethis_script() {

	wp_enqueue_script(
		'shareThis',
		get_template_directory_uri() . '/js/sharethis.js',
		array( 'jquery' )
	);
}

add_action( 'get_header', 'redox_sharethis_script' );



$use_infinite_scroll= get_option('redox_use_infinite_scroll');
if ($use_infinite_scroll == "true") {
		function redox_infinite_scroll() {
			wp_enqueue_script(
				'infinitescroll',
				get_template_directory_uri() . '/js/jquery.infinitescroll.min.js',
				array( 'jquery' )
			);
			wp_enqueue_script(
				'infinitescrolltrigger',
				get_template_directory_uri() . '/js/jquery.infinitescroll.trigger.js',
				array( 'jquery' )
			);
		}
		add_action( 'get_footer', 'redox_infinite_scroll' );
}				
	

function redox_footer_scripts(){ 
	$use_infinite_scroll= get_option('redox_use_infinite_scroll');
	$google_analytics = get_option('redox_google_analytics');
	$show_share_meta= get_option('redox_meta_share');
?>

<script type="text/javascript">
//<![CDATA[
    jQuery(function($) {
        $('.author-preview-thumbnail').click(function () {     			
            $('body').toggleClass('expansion-active'); 
        });
        $('.mini-trigger').click(function () {	
            $('body').toggleClass('expansion-active'); 
        });
        $('#body-cover').click(function () {
            $('body').removeClass('expansion-active'); 
        });
    });
//]]>	
</script>
<script type="text/javascript">
//<![CDATA[
    function centerImages() {
        jQuery(".gallery:not(.columns-1) .gallery-item:not(:first-child) img").each(function(){		
            var jQueryimg =  jQuery(this);
            var h =  jQuery(this).height();
            jQuery(this).css('margin-top', + h / -2 + "px"); 
        });
        jQuery(".gallery").fadeTo("slow", 1);
    }
    jQuery(window).load(function(){
        centerImages();
    });
    
    jQuery(function($) {
        
        $.Isotope.prototype._getCenteredMasonryColumns = function() {
            this.width = this.element.width();				 
            var parentWidth = this.element.parent().width();	
            var colW = this.options.masonry && this.options.masonry.columnWidth ||
            this.$filteredAtoms.outerWidth(true) ||
            parentWidth;
            var cols = Math.floor( parentWidth / colW );
            cols = Math.max( cols, 1 );
            this.masonry.cols = cols;
            this.masonry.columnWidth = colW;
        };

        $.Isotope.prototype._masonryReset = function() {
            this.masonry = {};
            this._getCenteredMasonryColumns();
            var i = this.masonry.cols;
            this.masonry.colYs = [];
            while (i--) {
                this.masonry.colYs.push( 0 );
            }
        };

        $.Isotope.prototype._masonryResizeChanged = function() {
            var prevColCount = this.masonry.cols;
            this._getCenteredMasonryColumns();
            return ( this.masonry.cols !== prevColCount );
        };

        $.Isotope.prototype._masonryGetContainerSize = function() {
            
            var unusedCols = 0,
            i = this.masonry.cols;
            while ( --i ) {
                if ( this.masonry.colYs[i] !== 0 ) {
                break;
                }
                unusedCols++;
            }
				    
            return {
                height : Math.max.apply( Math, this.masonry.colYs ),
                width : (this.masonry.cols - unusedCols) * this.masonry.columnWidth
            };
        };
        
        $(".gallery-icon a").fancybox();
        $('.post').fitVids();  
        var $window = $(window);
        var jQuerycontainer = jQuery('.content')
        var jQueryIScontainer = jQuery('.is-content.content')	
        jQuerycontainer.imagesLoaded( function(){
            jQuerycontainer.isotope({
                itemSelector : ".post",
                animationEngine : 'css',
                resizable: false
            });
            jQuery('.expansion').hide();
            jQuerycontainer.animate({ 
                opacity: 1 
            });
        });
        
        $(window).smartresize(function(){
            //var $windowSize = $(window).width();
            //if ($windowSize > 1090) {
                jQuerycontainer.isotope({
                    masonry: {
                        columnWidth: 224
                    }
                });
            //}   
            /*if ($windowSize < 1089) {
                jQuerycontainer.isotope({
                    masonry: {
                        columnWidth:  224
                    }
                });
            }
            if ($windowSize < 900 && $windowSize > 720 ) { 
                jQuerycontainer.isotope({
                    masonry: {
                        columnWidth:  250
                    }
                });
            };*/
        }).smartresize(); 
        
    <?php
        if ($use_infinite_scroll == "true") {
    ?>
        jQueryIScontainer.infinitescroll({
            navSelector  : '#is-more',
            nextSelector : '#is-more .next a',
            itemSelector : '.is.post',
            behavior: 'twitter',
            loading: {
                msgText: '',
                finishedMsg: '',
                selector: '#is-more',
                img: ''
            }
        },

        function( newElements ) {
            var $newElems = $( newElements ).css({ opacity: 0 });
            $newElems.imagesLoaded(function(){
                $newElems.animate({ opacity: 1 });
                jQueryIScontainer.isotope('appended', $newElems );

            });

            $(".gallery-icon a").fancybox();
            $('.is.post').fitVids();
            centerImages();
        }
    );
    <?php 
        }
    ?>

    });	
//]]>
</script>
		<?php 
			if ($use_infinite_scroll == "true") {
		?>
			<script type="text/javascript">
		    	//<![CDATA[
				jQuery(function($) {
                                    $('.top').click(function () {
                                            $('body,html').animate({
                                                    scrollTop: 0
                                            }, 800);
                                            return false;
                                    });
		   		});
		   		//]]>
		    </script>
		<?php 
			}
		?>
		<?php
			if ($show_share_meta == "true") {
		?>
		<script type="text/javascript">
		//<![CDATA[
			stLight.options({
				publisher: "ur-1502d7b-504f-e52a-5464-9218ac7a2684", doNotHash: false, doNotCopy: false, hashAddressBar: false
			});
		//]]>
		</script>
		<?php
			}
		?>
		 <?php
            echo $google_analytics;
		?>
	<?php
	}

	add_action('wp_footer', 'redox_footer_scripts'); 


//custom
add_image_size( 'rokbar_small', 224, 224, true ); 
add_image_size( 'rokbar_large', 448, 448, true );

function redox_grayscale_script() {
    wp_enqueue_script(
        'grayscale',
        get_template_directory_uri() . '/js/grayscale.js',
        array( 'jquery' )
    );
}

//add_action( 'get_header', 'redox_grayscale_script' );

if ( function_exists('register_sidebar') ) {
    register_sidebar(array('name'=>'Rockbar Header Right',
    'id' => 'rockbar_header_right_sidebar',
                            'description' => 'Rockbar Header Right Sidebar',
                            'before_widget' => '<div class="widget post">',
                            'after_widget' => '</div>',
                            'before_title' => '<h3 class="widget-title">',
                            'after_title' => '</h3>'
    ));
    register_sidebar(array('name'=>'Rockbar Footer Left',
    'id' => 'rockbar_footer_left_sidebar',
                            'description' => 'Rockbar Footer Left Sidebar',
                            'before_widget' => '<div class="widget post">',
                            'after_widget' => '</div>',
                            'before_title' => '<h3 class="widget-title">',
                            'after_title' => '</h3>'
    ));
    register_sidebar(array('name'=>'Rockbar Footer Right',
    'id' => 'rockbar_footer_right_sidebar',
                            'description' => 'Rockbar Footer Right Sidebar',
                            'before_widget' => '<div class="widget post">',
                            'after_widget' => '</div>',
                            'before_title' => '<h3 class="widget-title">',
                            'after_title' => '</h3>'
    ));
    register_sidebar(array('name'=>'Rockbar Footer Copyright',
    'id' => 'rockbar_footer_copyright_sidebar',
                            'description' => 'Rockbar Footer Copyright Sidebar',
                            'before_widget' => '<div class="widget post">',
                            'after_widget' => '</div>',
                            'before_title' => '<h3 class="widget-title">',
                            'after_title' => '</h3>'
    ));
}

function redox_custom_script() {
    wp_enqueue_script(
        'custom',
        get_template_directory_uri() . '/js/custom.js',
        array( 'jquery' )
    );
}

add_action( 'get_header', 'redox_custom_script' );

?>